package com.ruoyi.shop.MerchantActivities.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.shop.MerchantActivities.domain.MerchantActivities;
import com.ruoyi.shop.MerchantActivities.service.IMerchantActivitiesService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商家活动Controller
 * 
 * @author ruoyi
 * @date 2025-02-24
 */
@RestController
@RequestMapping("/activities")
public class MerchantActivitiesController extends BaseController
{
    @Autowired
    private IMerchantActivitiesService merchantActivitiesService;

    /**
     * 查询商家活动列表
     */
    @RequiresPermissions("shop:activities:list")
    @GetMapping("/list")
    public TableDataInfo list(MerchantActivities merchantActivities)
    {
        startPage();
        List<MerchantActivities> list = merchantActivitiesService.selectMerchantActivitiesList(merchantActivities);
        return getDataTable(list);
    }

    /**
     * 导出商家活动列表
     */
    @RequiresPermissions("shop:activities:export")
    @Log(title = "商家活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MerchantActivities merchantActivities)
    {
        List<MerchantActivities> list = merchantActivitiesService.selectMerchantActivitiesList(merchantActivities);
        ExcelUtil<MerchantActivities> util = new ExcelUtil<MerchantActivities>(MerchantActivities.class);
        util.exportExcel(response, list, "商家活动数据");
    }

    /**
     * 获取商家活动详细信息
     */
    @RequiresPermissions("shop:activities:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(merchantActivitiesService.selectMerchantActivitiesById(id));
    }

    /**
     * 新增商家活动
     */
    @RequiresPermissions("shop:activities:add")
    @Log(title = "商家活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MerchantActivities merchantActivities)
    {
        return toAjax(merchantActivitiesService.insertMerchantActivities(merchantActivities));
    }

    /**
     * 修改商家活动
     */
    @RequiresPermissions("shop:activities:edit")
    @Log(title = "商家活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MerchantActivities merchantActivities)
    {
        return toAjax(merchantActivitiesService.updateMerchantActivities(merchantActivities));
    }

    /**
     * 删除商家活动
     */
    @RequiresPermissions("shop:activities:remove")
    @Log(title = "商家活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(merchantActivitiesService.deleteMerchantActivitiesByIds(ids));
    }
}
